//
//  PasswordInputView.m
//  HuaRun2
//
//  Created by admin on 17/9/4.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "PasswordInputView.h"
#import "LineView.h"

@interface PasswordInputView ()
@property(nonatomic, strong)LineView * lineView;

@end

@implementation PasswordInputView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
#pragma mark - life cycle
- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {
    self.backgroundColor = kRandomColor;// [UIColor whiteColor];
    
    [self addSubview:self.nameLab];
    [self addSubview:self.iconView];
    [self addSubview:self.textField];
    [self addSubview:self.lineView];
    
}

- (void)layoutInit {
    weakself(ws);
    
    CGFloat height = 50;
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(ws.textField);
        make.height.mas_equalTo(  20);
        make.top.mas_equalTo(ws);
    }];
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws);
        make.size.mas_equalTo( CGSizeMake(15, 15));
        make.bottom.mas_equalTo(ws.lineView);
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws).offset(0);
        make.bottom.mas_equalTo(ws.mas_bottom);//.offset(kMargin10 / 2);
        make.right.mas_equalTo(ws).offset(0);
        make.height.mas_equalTo(25);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(ws);//.offset(-kMargin10/ 5);
        make.left.right.mas_equalTo(ws.textField).offset(0);
        make.height.mas_equalTo(1);
    }];
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(ws);
        make.height.mas_equalTo(height);
    }];
}

#pragma mark - getter

- (UIImageView *)iconView {
    if (!_iconView) {
        self.iconView = [UIImageView new];
        _iconView.image = [UIImage imageNamed:@"电话001"];
        _iconView.hidden = YES;
    }
    return _iconView;
}

- (UITextField *)textField {
    if (!_textField) {
        self.textField = [UITextField new];
        _textField.font = kGeneralFontSize;
//        _textField.backgroundColor = kRandomColor;
    }
    return _textField;
}
- (LineView *)lineView {
    if (!_lineView) {
        self.lineView = [LineView new];
    }
    return _lineView;
}
    
- (UILabel *)nameLab {
    if (!_nameLab) {
        self.nameLab = [UILabel new];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.font = kGeneralFontSize;
        _nameLab.textColor = [UIColor grayColor];
    }
    return _nameLab;
}

@end
